# encoding: utf-8
# @author: luzhangdan
# @file: base_api.py
# @time: 2021/10/19 15:12


from common.client import RequestClient


class BaseApi:
    login_token = None

    def __init__(self):
        """
        定义初始化的属性
        """
        self.client = RequestClient()
        self.url = None
        self.method = None
        # 定义统一使用的请求头header
        self.headers = None
        self.data = None
        self.params = None
        self.json = None
        self.files = None

    def send(self, **kwargs):
        """
        发送请求，如果参数中没有传具体的值，则使用初始化方法的属性
        :param kwargs: 字典
        :return: 接口响应接口
        """
        # 定义参数
        global url, method, data, params, json, files, headers
        if kwargs.get("url") == None:
            url = self.url
        if kwargs.get('method') == None:
            method = self.method
        if kwargs.get('headers') == None:
            headers = self.headers
        if kwargs.get('params') == None:
            params = self.params
        if kwargs.get('data') == None:
            data = self.data
        if kwargs.get('json') == None:
            json = self.json
        if kwargs.get('files') == None:
            files = self.files
        response = self.client.send_request(url=url, params=params, method=method, data=data, headers=headers,
                                            json=json, files=files)
        return response
